package databinding.demo.ui;

import android.databinding.DataBindingUtil;
import android.databinding.OnRebindCallback;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.transition.TransitionManager;
import android.view.View;
import android.view.ViewGroup;

import databinding.demo.R;
import databinding.demo.databinding.ActivityBindAnimationBinding;

/**
 * Created by dengdayi
 * Date: 2017/03/30 10：40
 */

public class BindAnimationActivity extends AppCompatActivity {
    ActivityBindAnimationBinding mBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_bind_animation);
        mBinding.setImageUrl("http://wmtp.net/wp-content/uploads/2016/07/1010689200fa918b241.jpg");
        mBinding.setPresenter(new Presenter());

        mBinding.addOnRebindCallback(new OnRebindCallback() {
            @Override
            public boolean onPreBind(ViewDataBinding binding) {
                ViewGroup group = (ViewGroup) binding.getRoot();
                TransitionManager.beginDelayedTransition(group);
                return true;
            }
        });
    }

    public class Presenter {
        public void onCheckedChanged(View buttonView, boolean isChecked) {
            mBinding.setShowImage(isChecked);
        }
    }
}
